package com.xxwy.springbootwebfluxclient;

import com.xxwy.springbootwebfluxclient.api.IUserApi;
import com.xxwy.api.interfaces.ProxyCreator;
import com.xxwy.api.proxy.JDKProxtCreator;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class SpringbootWebfluxclientApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringbootWebfluxclientApplication.class, args);
	}


	@Bean
	ProxyCreator jdkProxyCreator(){
		return new JDKProxtCreator();
	}

	@Bean
	FactoryBean<IUserApi> factoryBean(ProxyCreator proxyCreator){

		return new FactoryBean<IUserApi>() {
			/**
			 * 返回代理对象
			 * @return
			 */
			@Override
			public IUserApi getObject() throws Exception {
				return (IUserApi)proxyCreator.createProxy(this.getObjectType());
			}

			@Override
			public Class<?> getObjectType() {
				return IUserApi.class;
			}
		};
	}
}


